﻿<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ include file="/inc.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>闪耀先生系列 - 确认订单</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<!-- Bootstrap -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<!-- style -->
<link href="<%=basePath%>css/home.css" rel="stylesheet" />
</head>
<body>
	<div class="alert alert-danger" role="alert" id="error"
		style="display: none">
		<i class="fa fa-exclamation-triangle"></i> gggggggg
	</div>
	<s:if test='error != null'>
		<div class="error">
			<div class="alert alert-danger" role="alert">
				<i class="fa fa-exclamation-triangle"></i>
				<s:property value="error" />
			</div>
		</div>
		<!--E .error-->
	</s:if>
	<form class="form-horizontal" id="form"
		action="<%=basePath%>public/orderSingleAction!pay.action"
		method="post" encType="multipart/form-data">
		<s:hidden name="brand_id"></s:hidden>
		<s:hidden name="cloth_id"></s:hidden>
		<s:hidden name="openid"></s:hidden>
		<div class="container-fluid">
			<div class="wrap">
				<div class="order-list" style="padding-top: 15px;">
					<div class="row">
						<div class="col-xs-3">
							<img src="<%=basePath_org%><s:property value="cloth.img" />"
								alt="">
						</div>
						<div class="col-xs-9">
							<div class="name">
								<s:property value="cloth.name" />
							</div>
							<p class="red">
								价格：
								<s:property value="brand.price" />
								元
							</p>
						</div>
					</div>
				</div>
				<!--E .order-list-->
				<div class="dizhi">
					<h3>会员信息</h3>
					<div class="form-group has-error">
						<s:textfield id="name" name="name" cssClass="form-control"
							placeholder="收货人" />
					</div>
					<div class="form-group has-error">
						<s:textfield id="address" name="address" cssClass="form-control"
							placeholder="收货地址" />
					</div>
					<div class="form-group has-error">
						<s:textfield id="phone" name="phone" cssClass="form-control"
							placeholder="手机号" />
					</div>
				</div>
				<!--E .dizhi-->
				<s:if test="brandVip.fd4sm == '10'">
				<div class="checkbox" style='display:none'>
			        <label>
			          <s:checkbox id="fd4sm" name="fd4sm" value="true" /> 是否使用上门券
			        </label>
			     </div>
			     </s:if>
				<s:if test="brandVip.fd4cs == '10'">
				<div class="checkbox">
			        <label>
			          <s:checkbox id="fd4cs" name="fd4cs" value="true" /> 是否使用衬衫券
			        </label>
			        <p>可使用衬衫券进行抵扣</p>
			     </div>
			     </s:if>
					<div class="checkbox">
						<label>
						<s:checkbox id="call" name="call" value="true" />
							选择预付10%，客服与你沟通确认后再付清全款；预付款随时可退。
						</label>
					</div>
				<button type="button" class="btn btn-org btn-lg btn-block"
					onclick="CreateOrder()">微信支付</button>
			</div>
			<!--E .wrap-->

		</div>
	</form>

	<script src="<%=basePath%>js/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
	//$("#call").click();
	//	$('#myModal,myModal1').modal(options);
	</script>
	<script>
	
    
    
            function CreateOrder() {
            	 var errorDiv = document.getElementById("error");
            	 errorDiv.style.display = "none";
            	 var name = document.getElementById('name').value;
            	 if(!name) {//a为null 或者"" 或者0 
            		 document.getElementById('error').innerHTML='请输入收货人';
            		 errorDiv.style.display = "block";
            		 return;
            	}
            	 var address = document.getElementById('address').value;
            	 if(!address) {//a为null 或者"" 或者0 
            		 document.getElementById('error').innerHTML='请输收货地址';
            		 errorDiv.style.display = "block";
            		 return;
            	}
            	 var phone = document.getElementById('phone').value;
            	 if(!phone) {//a为null 或者"" 或者0 
            		 document.getElementById('error').innerHTML='请输手机号';
            		 errorDiv.style.display = "block";
            		 return;
            	}
           
           
            	 
            	 
			 var brand_id = document.getElementById('brand_id').value;
			 var openid = document.getElementById('openid').value;
			var cloth_id = document.getElementById('cloth_id').value;
			var fd4sm =  document.getElementById('fd4sm') == null?"false":document.getElementById('fd4sm').checked;
			var fd4cs =  document.getElementById('fd4cs') == null?"false":document.getElementById('fd4cs').checked;
					$.ajax({
						type:'post',
						url:'<%=basePath%>public/orderSingleAction!pay.action',
						dataType : 'json', 
						data : {"fd4cs":fd4cs,"fd4sm":fd4sm,"cloth_id":cloth_id,"brand_id":brand_id,"name":name,"address":address,"phone":phone,"openid":openid},
						timeout:60000,
						success: function (json_str){
							  var temp = eval(json_str);  
							  if(temp.code != "success"){
								  alert(temp.message);
							  }else{
								  WeixinJSBridge.invoke('getBrandWCPayRequest',
									  	   {
									  	   "appId" : temp.appId,     //公众号名称，由商户传入     
								           "timeStamp":temp.timeStamp,         //时间戳，自1970年以来的秒数     
								           "nonceStr" : temp.nonceStr, //随机串     
								           "package" : temp.package,     
								           "signType" : "MD5",         //微信签名方式:     
								           "paySign" : temp.paySign//微信签名 
									  	   },
									  	  function(res){
					                          if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					                        	//交易成功
					                        	  _updateOrder(temp.fdOrderId);
					                          }else{
					                          	alert("交易失败!");
					                          }
					                          // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
					                          //因此微信团队建议，当收到ok返回时，向商户后台询问是否收到交易成功的通知，若收到通知，前端展示交易成功的界面；若此时未收到通知，商户后台主动调用查询订单接口，查询订单的当前状态，并反馈给前端展示相应的界面。
				                          }); 
							  }
							  
						}
					});
	}  
function checkOrder(){
	var brand_id = document.getElementById('brand_id').value;
	var openid = document.getElementById('openid').value;
	$.ajax({
		type:'post',
		url:'<%=basePath%>public/orderSingleAction!checkOrder.action',
		dataType : 'json', 
		data : {"brand_id":brand_id,"openid":openid},
		timeout:60000,
		success: function (json_str){
			var temp = eval(json_str); 
			if(temp.code != "success"){
				alert(temp.message);
			}else{
				CreateOrder();
			}
			
		}
	});
}	
function _updateOrder(fdOrderId){
	var openid = document.getElementById('openid').value;
	 $.ajax({
			type:'post',
			url:'<%=basePath%>public/orderSingleAction!updateOrder.action',
						dataType : 'json',
						data : {
							"fdOrderId" : fdOrderId,"openid":openid
						},
						timeout : 60000,
						success : function(json_str) {
							 var temp = eval(json_str);  
							 //alert(temp.message); 
							 location.href = "${pageContext.request.contextPath}/public/brandAction!view.action";
						}
					});
		}
	</script>
</body>
</html>